home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12110 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.6 KB  |  49 lines

  1. Newsgroups: comp.lang.c++
  2. Path: netcom.com!mikenann
  3. From: Michael Glassman and Ann Ross <mikenann@netcom.com>
  4. Subject: Re: extern consts
  5. Content-Type: text/plain; charset=us-ascii
  6. Message-ID: <314CE209.59EB@netcom.com>
  7. Sender: mikenann@netcom16.netcom.com
  8. Content-Transfer-Encoding: 7bit
  9. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  10. References: <4idbcv$ue2@news7.erols.com> <314c2077.138956468@nntp.ix.netcom.com> <4ii7h9$bq6@news6.erols.com>
  11. Mime-Version: 1.0
  12. Date: Mon, 18 Mar 1996 04:09:45 GMT
  13. X-Mailer: Mozilla 2.0 (Win16; I)
  14.  
  15. Chris Cobb wrote:
  16. > miker3@ix.netcom.com (Mike Rubenstein) wrote:
  17. > >
  18. > >It's not legal.  extern const is legal, but in any compilation unit
  19. > >that does not see the initializer the const variable is not a constant
  20. > >expression.
  21. > >
  22. > Well, your comment makes sense.  However, in a way it seem
  23. > self-contradictory.  If a const can be extern, then it no longer is a
  24. > const: you've basically externed away constness.  But if thats what
  25. > externinig a const does, it doesn't make sense to allow it at all (which
  26. > is what happens on most compilers.)
  27. > Chris
  28.  
  29. Why do you say that extern'ing a const removes its 'constness'? Extern in this case 
  30. just refers to external linkage and global scope. This is required since const 
  31. defaults to 'static' which is file scope. It is still illegal to attempt to change the 
  32. value. 
  33.  
  34. The method for making a global constant is:
  35.  
  36.     file.CC
  37.         extern const float PI=3.14159;
  38.  
  39.     file.h 
  40.         extern const float PI;
  41.  
  42. Including file.h and linking with file.o will give routines access to the global 
  43. constant PI.
  44.  
  45. Michael Glassman
  46.